﻿@{
    ViewBag.Title = "TagList";
}
@model IEnumerable<CW_Tag>

<h2>标签List</h2>
<div>
    @Html.ActionLink("新增文章", "ArticleCreate", null, new { Class = "btn btn-primary" })
</div>
<hr />
@using (Html.BeginForm("TagCreate", "Admin", FormMethod.Post, new { id = "form1", Class = "from", onsubmit = "return checkInput();", enctype = "multipart/form-data" }))
{
   
        <input type="text" class="form-control" name="TagName" id="TagName" style="width:200px;display:inline-block" data-rule-required='true' data-msg-required="请输入标签" placeholder="标签">
        <input type="hidden" name="TagId" id="TagId" >
    
    <button type="submit" id="btnEdit" class="btn btn-default">添加</button>
}
<hr />
<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
            <tr>
                <th>#</th>
                <th>标签</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.CheckBox("TagId", false, new { value = @item.TagId })
                    </td>
                    <td>
                        @item.TagName
                    </td>
                    <td>                        
                        <input type="button" value="修改" class="btn btn-default" onclick="editItem(this,@item.TagId,'@item.TagName')" />
                        @using (Html.BeginForm("TagDelete", "Admin", new { id = @item.TagId }, FormMethod.Post, new { onsubmit = "return marksure();", style = "display:inline-block" }))
                        {
                            <input type="submit" class="btn btn-default" value="删除" />
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>
@section Scripts {
    <script src="~/scripts/jquery.validate.min.js"></script>
    <script src="~/scripts/jquery.form.js"></script>    
    <script>
        $(function () {
            validateCN();
        })
        function validateCN() {
            $("form").validate({
                errorClass: "text-danger text-sm",
                errorPlacement: function (error, element) {
                    element.after(error);
                }
            });
        }
        function checkInput() {
            return $("#form1").valid();
        }
        function editItem(obj, id, name) {
            $("#TagId").val(id);
            $("#TagName").val(name);
            $("#btnEdit").text("修改");
        }     
    </script>
}


